package com.dtt.company.init;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
//page包下的文件限制--登录之后才能访问
@WebFilter("/web/page/*")
public class UserFilter implements Filter{
//防盗链
	
	@Override
	public void doFilter(ServletRequest req,ServletResponse resp, FilterChain chain)
			throws IOException, ServletException {
		//session.setAttribute("user",user);
		HttpServletRequest request=(HttpServletRequest)req;
		HttpSession session=request.getSession();
		Object user=session.getAttribute("user");
		if(user==null) {
			req.getRequestDispatcher("/web/login.jsp").forward(request, resp);
			//跳转页面
			//request.getRequestDispatcher("").forward(request, rqsp);
			//((HttpServletResponse)resp).sendRedirect("");
			
		}else {
			chain.doFilter(req,resp);
		}
	} 

}
